package com.demo.tools;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ObjectMapperFactory
{

    private static volatile Map<String, ObjectMapper> mapperMap = new ConcurrentHashMap<String, ObjectMapper>();

    private static volatile ObjectMapper objectMapper = null;

    public static ObjectMapper getObjectMapper(Class tClass)
    {
        ObjectMapper objectMapper = null;

        if (mapperMap.containsKey(tClass.getName()))
        {
            objectMapper = mapperMap.get(tClass.getName());

        }
        else
        {
            objectMapper = new ObjectMapper();
            mapperMap.put(tClass.getName(), objectMapper);
        }
        return objectMapper;

    }

    public static ObjectMapper getObjectMapper()
    {
        if (objectMapper == null)
        {
            objectMapper = new ObjectMapper();
        }
        return objectMapper;
    }
}
